package com.example.smartcity1.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.smartcity1.R;
import com.example.smartcity1.bean.MyOrderBean;

import java.util.List;

public class MyOrderAdapter extends ArrayAdapter<MyOrderBean.DataDTO> {

    private static final String TAG = "MyOrderAdapter";



    public MyOrderAdapter(@NonNull Context context, int resource, @NonNull List<MyOrderBean.DataDTO> objects) {
        super(context, resource, objects);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_my_order_all,parent,false);
            viewHolder = new ViewHolder();
            viewHolder.itemMyOrderPath = convertView.findViewById(R.id.item_my_order_path);
            viewHolder.itemMyOrderStart = convertView.findViewById(R.id.item_my_order_start);
            viewHolder.itemMyOrderEnd = convertView.findViewById(R.id.item_my_order_end);
            viewHolder.itemMyOrderOrderNum = convertView.findViewById(R.id.item_my_order_orderNum);
            viewHolder.itemMyOrderPrice = convertView.findViewById(R.id.item_my_order_price);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        MyOrderBean.DataDTO data = getItem(position);
        if (data != null) {
            viewHolder.itemMyOrderPath.setText(data.getPath());
            viewHolder.itemMyOrderStart.setText(data.getStart());
            viewHolder.itemMyOrderEnd.setText(data.getEnd());
            viewHolder.itemMyOrderOrderNum.setText(String.format("订单号:%s", data.getOrderNum()));
            viewHolder.itemMyOrderPrice.setText(String.format("￥ %s 元", data.getPrice().toString()));
        }


        return convertView;
    }



    private class ViewHolder {
        TextView itemMyOrderPath;
        TextView itemMyOrderStart;
        TextView itemMyOrderEnd;
        TextView itemMyOrderOrderNum;
        TextView itemMyOrderPrice;
    }
}
